import numpy as np
import cv2

flags = [i for i in dir(cv2) if i.startswith('COLOR_')]
print(flags)


img = cv2.imread('opencv.png')

# Convert BGR to HSV
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)

# define range of blue color in HSV
lower_blue = np.array([110, 50, 50])
upper_blue = np.array([130, 255, 255])

# Threshold the HSV image to get only blue colors
mask = cv2.inRange(hsv, lower_blue, upper_blue)

# Bitwise-AND mask and original image
res = cv2.bitwise_and(img, img, mask=mask)
cv2.imwrite('opencv_hsv.png', res)

# 如何知道颜色的hsv值呢，参考如下方法
green = np.uint8([[[0,255,0 ]]])
hsv_green = cv2.cvtColor(green,cv2.COLOR_BGR2HSV)
# [[[ 60 255 255]]]
print(hsv_green)
